<?php

namespace App\Http\Controllers;
use App\Providers\testProviders;
use App\Services\test;
use Barryvdh\Snappy\Facades\SnappyImage;
use Barryvdh\Snappy\Facades\SnappyPdf;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\App;
use niklasravnsborg\LaravelPdf\Facades\Pdf;

class TestController extends Controller
{

    public function __construct(test $aa)
    {

    }

    //测试服务
//    public function test()
//    {
//        $test = new test();
//        dd($test::test());
//    }

    public function test1()
    {
//       $test = App::make('test111s');
        $test = app('test111s')->test1();
//        $test = $test->test1();
//         $test = test::test1();
        dd($test);
    }

    public function test3()
    {
        $url = "file:///C:/Users/Administrator/Desktop/logo.jpg";
        $ch = curl_init();
        //这里返回响应报文时，只要body的内容，其他的都不要
        curl_setopt($ch, CURLOPT_URL,$url);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_NOBODY, 0);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        $package = curl_exec($ch);
          //获取curl连接句柄的信息
        $httpInfo = curl_getinfo($ch);
        curl_close($ch);
        $info = array_merge(array($package), array($httpInfo));
        dd($info);
    }

    public function test4()
    {
        $aa = '11';
        return view('test');
//        view('test',compact('aa'));
    }

    public function test5(Request $request)
    {
        $data = $request->data;
        $img = str_replace('data:image/png;base64,', '', $data);
        $img = str_replace(' ', '+', $img);
        $data = base64_decode($img);
        $file = uniqid() . '.png';
        $success = file_put_contents('img/'.$file, $data);
        dd($file);
        dd($success);

        dd($data);
    }

    public function test6()
    {
        $pdf = Pdf::loadView('test');
        
        return $pdf->stream('document.pdf');
    }

    public function test7()
    {
        $da['abc'] = "啊啊啊啊啊啊啊啊啊";
        $da['bcd'] = "啊啊啊啊啊啊啊啊啊";
//        $data = SnappyImage::loadView('test',$da);
//        $data = PDF::loadView('test', $da);
        $data = SnappyPdf::loadView('test', $da);
        $file = uniqid() . '.pdf';
        $data->save('img/'.$file, true);
        //return $data = $data->download($file);
//        file_put_contents('img/'.$file, $data);
    }
}
